{* FILTERS *}

<script language="javascript">
	function addfilter(field,value) {ldelim}
		var forma = document.getElementById("list_form");
		var f = document.getElementById(field);
		f.value=value;		
		forma.submit();
	{rdelim}
	function updateRequest(id,action) {ldelim}
		var forma = document.getElementById("list_form");
		forma.op.value=action;
		forma.id.value=id;
		forma.submit();
	{rdelim}
	function startEdit(id,team,start, end) {ldelim}
		var forma = document.getElementById("message_form");
		var msg = document.getElementById("m"+id).innerHTML;
		forma.id.value=id;
		forma.op.value='edit';
		forma.teamid.value=team;
		forma.message.value=msg;
		
		forma.showstart.value = start;
		forma.showend.value = end;
		
		{*
		forma.showstarta.value=start.substr(0,4);
		if (start.substr(5,1)==0) {ldelim}
			forma.showstartm.value=start.substr(6,1);
		{rdelim} else {ldelim}
			forma.showstartm.value=start.substr(5,2);
		{rdelim}
		if (start.substr(8,1)==0) {ldelim}
			forma.showstartd.value=start.substr(9,1);
		{rdelim} else {ldelim}
			forma.showstartd.value=start.substr(8,2);
		{rdelim}

		forma.showenda.value=end.substr(0,4);
		if (end.substr(5,1)==0) {ldelim}
			forma.showendm.value=end.substr(6,1);
		{rdelim} else {ldelim}
			forma.showendm.value=end.substr(5,2);
		{rdelim}		
		if (end.substr(8,1)==0) {ldelim}
			forma.showendd.value=end.substr(9,1);
		{rdelim} else {ldelim}
			forma.showendd.value=end.substr(8,2);
		{rdelim}
		*}
		document.getElementById("edit_form").style.display = '';
		document.getElementById("add_form").style.display = 'none';
	{rdelim}
	function cancelEdit() {ldelim}
		var forma = document.getElementById("message_form");
		forma.op.value='add';
		forma.id.value='';
		forma.teamid.value='0';
		forma.message.value='';
		forma.showstart.value='';
		forma.showend.value='';
		document.getElementById("edit_form").style.display = 'none';
		document.getElementById("add_form").style.display = '';
	{rdelim}

	function validate(form) {ldelim}
		var forma = document.getElementById(form);
		var valid=true;

		var el = getDateFromString(forma.showstart.value,'{$dateformat}');
		var desde=new Date();
		desde.setFullYear(el.year,el.month,el.day);

		el = getDateFromString(forma.showend.value,'{$dateformat}');
		var hasta=new Date();
		hasta.setFullYear(el.year,el.month,el.day);
		
		{*		
		var m = forma.showstartm.value;
		var d = forma.showstartd.value;
		if (m<10) {ldelim}
			m='0'+m;
		{rdelim}
		if (d<10) {ldelim}
			d='0'+d;
		{rdelim}		
		var desde = forma.showstarta.value + m + d;

		var m = forma.showendm.value;
		var d = forma.showendd.value;
		if (m<10) {ldelim}
			m='0'+m;
		{rdelim}
		if (d<10) {ldelim}
			d='0'+d;
		{rdelim}
		var hasta = forma.showenda.value + m + d;	
		*}
		if (hasta<=desde) {ldelim}
			valid=false;
			alert('{$lang.invaliddate}');
		{rdelim} else if (forma.message.value=='') {ldelim}
			valid=false;
			alert('{$lang.messagemissing}');
		{rdelim}
		if (valid) processForm(form);
	
	{rdelim}
	
	var cald = new CalendarPopup();
	cald.setReturnFunction("setMultipleValuesd");

	var calh = new CalendarPopup();
	calh.setReturnFunction("setMultipleValuesh");

	function setMultipleValuesd(y,m,d) {ldelim}
		document.getElementById("showstarta")=y;
		document.getElementById("showstartm")=LZ(m);
		document.getElementById("showstartd")=LZ(d);
    {rdelim}

	function setMultipleValuesh(y,m,d) {ldelim}
		document.getElementById("showenda")=y;
		document.getElementById("showendm")=LZ(m);
		document.getElementById("showendd")=LZ(d);
    {rdelim}

	function showMessage(e,id) {ldelim}
		document.getElementById('message_div_content').innerHTML=document.getElementById("m"+id).innerHTML;;
		openDiv(e,'messagediv');
	{rdelim}
	
	function deleteItem() {ldelim}
		if (confirm('{$lang.confirmdelete}')) {ldelim} 
			updateRequest('','remove')
		{rdelim}	
	{rdelim}
	
</script>

<center>

<form method="post" id="message_form">
	<input type="hidden" name="flowid" id="flowid" value="{$flowid}">
	<input type="hidden" name="action" id="action" value="messageadmin">
	<input type="hidden" name="op" id="op" value="add">
	<input type="hidden" name="id" id="id" value="">	
	 <table width="100%" cellpadding="0" cellspacing="0">
	   {if $CURRENT_USER->groupid eq 'ADMIN'}
		   <tr>
			 <td>&nbsp;{$lang.team}</td>
			 <td>
				<select name="teamid" id="teamid" class="txt">
					<option value="0">{$lang.everyone}</option>
					{foreach from=$teamlist item=op}
						<option value="{$op->id}">{$op->name}</option>
					{/foreach}
				</select>			 
			</tr>
	   {else}
			<input type="hidden" name="teamid" id="teamid" value="{$CURRENT_USER->teamid}">	   
	   {/if}
	   <tr>
		 <td>&nbsp;{$lang.showstart}</td>
		 <td>
		 	<input type="text" size="12" readonly name="showstart" id="showstart" class="txt">
		 	<img style="position:absolute" src="images/calendar.png" alt="Calendar" width="24" height="24" onclick="displayCalendar(document.forms['message_form'].showstart,'{$dateformat}',this,false,'undefined','{$CURRENT_USER->lang}')">
		 </td>
		</tr>
	   <tr>
		 <td>&nbsp;{$lang.showend}</td>
		 <td>
	 		<input type="text" size="12" readonly name="showend" id="showend" class="txt">
			<img style="position:absolute" src="images/calendar.png" alt="Calendar" width="24" height="24" onclick="displayCalendar(document.forms['message_form'].showend,'{$dateformat}',this,false,false,'{$CURRENT_USER->lang}')">
		 </td>
		</tr>		
	   <tr>
		 <td valign="top">&nbsp;{$lang.message}</td>
		 <td>
		 	<textarea class="txt" name="message" id="message" rows="5" cols="20" wrap="off"></textarea>
		 </td>
		</tr>
			 <td align="right" colspan="2">
			 <div id="add_form">
			 {include file="button.tpl" name=$lang.new action="validate('message_form')"}
			 </div>
			 <div id="edit_form" style="display: none;">
			 {include file="button.tpl" name=$lang.ok action="validate('message_form')"}
			 &nbsp;{include file="button.tpl" name=$lang.cancel action="cancelEdit()"}
			 </div>
			 </td>
	   </tr>
	 </table>	
</form>
</center>


<center>
<form method="post" id="list_form">
	<input type="hidden" name="flowid" id="flowid" value="{$flowid}">
	<input type="hidden" name="action" id="action" value="messageadmin">
	<input type="hidden" name="op" id="op" value="">	
	<input type="hidden" name="id" id="id" value="">
<table align="center" width="100%" border="0" cellpadding="0" cellspacing="0">

	<thead>
		<tr>
			<th>&nbsp;</th>
			<th>{$lang.team}</th>
			<th>{$lang.showstart}</th>
			<th>{$lang.showend}</th>
			<th>{$lang.status}</th>
			<th>&nbsp;</th>
			<th>
				<img src="images/arrowdown.png" alt="" width="18" height="18" class="link" onclick="checkAll('itemid[]')">
				<img src="images/arrowup.png" alt="" width="18" height="18" class="link" onclick="uncheckAll('itemid[]')">
			</th>
		</tr>
	</thead>

	{* TABLE BODY - DYNAMIC *}
	<tbody>
		{assign var="rowclass" value="uneven"}
		{foreach from=$list item=row}
			{eval var=$row->status assign="stid"}
			<tr class="{$rowclass}" {if $stid neq 'ACTIVE'} style="font-style: italic" {/if}>
				<td><span class="link" onclick="showMessage(event,'{$row->id}')"><img src="images/postit.gif" width="18" height="18"></span>
				{if $row->teamid eq 0 }
					<td>{$lang.everyone}</td>
				{else}
					<td>{$row->team->name}</td>
				{/if}
				<td>{$row->showstartf}</td>
				<td>{$row->showendf}</td>				
				<td>{$lang.$stid}</td>
				<td>
					<span onclick="startEdit('{$row->id}','{$row->teamid}','{$row->showstartf}','{$row->showendf}')" class="link">{$lang.edit}</span>
				</td> 
				<td align="center">
					<input type="checkbox" class="txt" name="itemid[]" id="itemid[]" value="{$row->id}" />
				</td>
				<div id="m{$row->id}" style="display: none;">{$row->message}</div> 
			</tr>
			{if $rowclass eq 'even'}
				{assign var="rowclass" value="uneven"}
			{else}
				{assign var="rowclass" value="even"}
			{/if}				
		{/foreach}

	</tbody>

	<tfoot>
		<tr>
			<th colspan="7">
				{include file="button.tpl" name=$lang.deactivate action="updateRequest('','deact')"}
				{include file="button.tpl" name=$lang.activate action="updateRequest('','act')"}
				{include file="button.tpl" name=$lang.remove action="deleteItem()"}
			</th>
		</tr>
	</tfoot>
	
</table>
</form>
<center>

<div name="messagediv" id="messagediv" style="display: none;" class="floatingform">
{include file="close.tpl" element="messagediv"}
<div id="message_div_content"></div>
</div>


